package cn.huyanbing.middleware.lock;

/**
 * @BelongProject middleware
 * @BelongPackage cn.huyanbing.middleware.lock
 * @Description TODO
 * @ClassName SynchronizedExample
 * @Author huyangbing
 * @Date 2025/2/10 10:04
 * @Version 1.0.0
 */
public class SynchronizedExample {

    int a = 0;
    boolean flag = false;

    //获取锁

    public synchronized void writer() {
        a = 1;
        flag = true;
    }
    //释放锁


    //获取锁
    public synchronized void reader() {
        if (flag) {
            int i = a;
        }
    }
    //释放锁
}
